<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\model\Banner;
use app\common\model\Department as ModelDepartment;
use app\common\model\Hospital as HospitalModel;
use app\common\model\Notice;
use fast\Tree;

/**
 * 科室接口
 */
class Department extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 科室列表
     *
     */
    public function list()
    {
        $params = request()->param();
        extract($params);
        if (!$id) {
            $this->error('参数错误');
        }
        $hospital = new HospitalModel;

        $dep_ids = $hospital->where('id', $id)->value('dep_ids');
        $data =collection( ModelDepartment::whereIn('id|pid', $dep_ids)->select())->toArray();
        $tree = Tree::instance();
        $tree->init($data, 'pid');
        $list = $tree->getTreeArray(0);
        $this->success('请求成功',$list);
    }


}
